{$CLEO .cs}
thread 'AI_AT400'
9@ = 0 //transmitter
7@ = -1 //plane
8@ = -1 //actor
10@ = -1 //plane marker
11@ = -1 //pathID
12@ = -1 //pathDetector
27@ = -1 //long angle
26@ = -1 //long coord
25@ = -1 //long coord
24@ = -1 //long coord

0@ = -1 //coord
1@ = -1 //coord
2@ = -1 //coord
3@ = -1 //temp value
4@ = -1 //angle
5@ = -1 //health
6@ = -1 //speed

:start
wait 0
if
Player.Defined($PLAYER_CHAR)
jf @start
if
80FE:   not actor $PLAYER_ACTOR sphere 0 in_sphere 1577.5233 -2493.5564 13.4705 radius 250.0 250.0 250.0
jf @start

:ava
wait 10
if
Model.Available(#AT400)
jf @load
wait 10
if
Model.Available(#WMYPLT)
jf @load1
jump @available

:load
Model.Load(#AT400)
wait 10
jump @ava

:load1
Model.Load(#WMYPLT)
wait 10
jump @ava

:available
Car.Create(7@, #AT400, 1577.5233, -2493.5564, 13.4705)
Car.Angle(7@) = 270.0
08E6: set_plane 7@ landing_gear 0 
0129: 8@ = create_actor_pedtype 4 model #WMYPLT in_car 7@ driverseat
Model.Destroy(#WMYPLT)
Model.Destroy(#AT400)
11@ = 46          //pathID
12@ = 0           //pathDetect
27@ = 270.0       //angle
26@ = 1577.5233  //longterm coords
25@ = -2493.5564 //longterm coords
24@ = 13.4705    //longterm coords
if
9@ == 1
jf @loadpath
0ACE: show_formatted_text_box "AT400 respawned at Los Santos."
Marker.CreateAboveaCTOR(10@, 8@)
Marker.SetColor(10@, 0)

:loadpath
3@ = 0 //wait
if
9@ == 1
jf @assign
0ACE: show_formatted_text_box "AT400 is waiting for passengers."

:assign
gosub @dead
gosub @transmit
gosub @passenger
Car.PutAt(7@, 26@, 25@, 24@)
Car.Angle(7@) = 27@
3@ += 1
if
3@ == 1500
jf @assign

:pathava
wait 10
if 
07C1:   path 11@ available
jf @loadpath1
jump @movingon

:loadpath1
07C0: load_path 11@
wait 10
jump @pathava

:movingon
05EB: assign_car 7@ to_path 11@
0873: release_path 11@
if
9@ == 1
jf @checks
0ACE: show_formatted_text_box "AT400 is now taking off."

:checks
gosub @dead
gosub @transmit
gosub @landinggear
if
860E:   not car 7@ assigned_to_path
jf @checks

:release
06C5: release_car 7@ from_path
12@ += 1
if
0029:   12@ >= 3
jf @detectpath
jump @repeat

:detectpath
3@ = 0
if
12@ == 1
jf @detectpath1
26@ = 1476.4661
25@ = 1718.7635
24@ = 10.7288
27@ = 0.0
gosub @angle
27@ = 180.0
if
9@ == 1
jf @putat
0ACE: show_formatted_text_box "AT400 is now in Las Venturas."

:putat
gosub @dead
gosub @transmit
3@ += 1 
25@ -= 0.5 
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@, 25@, 24@)
if 
3@ == 152
jf @putat 
26@ = 1475.7020
25@ = 1642.6296
24@ = 10.7448
11@ = 43
jump @loadpath

:detectpath1
if
12@ == 2
jf @repeat
26@ = -1542.3070
25@ = -47.1985
24@ = 14.0603
27@ = 135.0
if
9@ == 1
jf @putat1
0ACE: show_formatted_text_box "AT400 is now in San Fierro."

:putat1
gosub @dead
gosub @transmit 
3@ += 1 
26@ -= 0.5 
25@ -= 0.5
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@, 25@, 24@)
if 
  3@ == 175 
else_jump @putat1
26@ = -1627.5796
25@ = -138.8973
24@ = 14.0598 
gosub @angle
27@ = 315.0
11@ = 49
jump @loadpath

:repeat
26@ = 1993.1895
25@ = -2488.1265
24@ = 13.4627
27@ = 270.0
gosub @angle
27@ = 90.0
if
3@ == 1
jf @repeat1
0ACE: show_formatted_text_box "AT400 is now in Los Santos."

:repeat1
gosub @dead 
gosub @transmit
3@ += 1
26@ += -0.5
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@,25@,24@)
if
3@ == 831
jf @repeat1
11@ = 46
12@ = 0
26@ = 1577.5233
25@ = -2493.5564 
24@ = 13.4705
27@ = 90.0
gosub @angle
27@ = 270.0
jump @loadpath

:passenger
if and
not Actor.Driving($PLAYER_ACTOR)
0205:   actor $PLAYER_ACTOR near_car 7@ radius 25.0 25.0 10.0 flag 0
00E1:   player 0 pressed_key 8
0AA1: return_if_false
0430: put_actor $PLAYER_ACTOR into_car 7@ passenger_seat 0
0051: return

:landinggear
Car.StorePos(7@, 0@, 1@, 2@)
if
2@ >= 50.0
jf @landinggear1
08E6: set_plane 7@ landing_gear 1
return

:landinggear1
08E6: set_plane 7@ landing_gear 0
return

:angle
3@ = 0

:angle2
gosub @dead
gosub @transmit 
000B: 27@ += 1.0
000A: 3@ += 1
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@, 25@, 24@)
if 
   3@ >= 180 
else_jump @angle2
3@ = 0
return

:dead
wait 0
if and
not 7@ == -1
not 8@ == -1
jf @ende
if and
not Car.Wrecked(7@)
0185:  car 7@ health >= 250
not Actor.Dead(8@)
Actor.InCar(8@, 7@)
jf @end
return

:end
0ABF: set_vehicle 7@ engine_state_to 0
Actor.RemoveReferences(8@)
Car.RemoveReferences(7@)
06C5: release_car 7@ from_path
if
9@ == 1
jf @start
0ACE: show_formatted_text_box "Something very bad happened to the AT400." 
Marker.Disable(10@)
jump @start

:ende
Marker.Disable(10@)
Actor.RemoveReferences(8@)
Car.RemoveReferences(7@)
jump @start

:transmit
if
0ADC: test_cheat "AT400"
jf @info
if
9@ == 0
jf @off
9@ = 1
Marker.CreateAboveActor(10@, 8@)
Marker.SetColor(10@, 0)
0ACE: show_formatted_text_box "AT400 transmitter online. Type AT400 again to turn off or hold H and 1 to view info."
return

:off
9@ = 0
Marker.Disable(10@)
0ACE: show_formatted_text_box "AT400 transmitter offline. Type AT400 to turn on."
return

:info
if
0AB0:  key_pressed 72
0aa1:
if
0AB0:  key_pressed 49
0aa1:
if
9@ == 1
0AA1: return_if_false
0227: 5@ = car 7@ health
02E3: 6@ = car 7@ speed
Car.StorePos(7@, 0@, 1@, 2@)
4@ = Car.Angle(7@)
0ACE: show_formatted_text_box "AT400 Health %d Speed %f at %f %f %f Angle %f" 5@ 6@ 0@ 1@ 2@ 4@
return